Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pyomo for NumPy 2 #3292

Merged
merged 7 commits into from
Jun 25, 2024
Merged

Update Pyomo for NumPy 2 #3292

merged 7 commits into from
Jun 25, 2024

Conversation

mrmundt
Copy link
Contributor

@mrmundt mrmundt commented Jun 17, 2024

Fixes #3290

Summary/Motivation:

Add in the updates for NumPy 2.

Changes proposed in this PR:

  • Change defaults / check for removed attributes
  • Update tests

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One (mostly stylistic) question

pyomo/common/dependencies.py Outdated Show resolved Hide resolved
@mrmundt
Copy link
Contributor Author

mrmundt commented Jun 17, 2024

FYI for anyone watching this PR: it needs some work on the NL writer's processing of NumPy representations. @jsiirola is going to look at it soon.

@mrmundt mrmundt requested a review from jsiirola June 17, 2024 18:50
Comment on lines -19 to +22
numpy_bool_names.append('bool_')
if numpy.__version__[0] == '2':
numpy_bool_names.append('bool')
else:
numpy_bool_names.append('bool_')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check version here, but everywhere else you use hasattr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because John added that one...

Copy link
Contributor Author

@mrmundt mrmundt Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh but also, I can answer - this is a forwards-compatible one. bool and bool_ are both valid in NumPy 2, whereas bool does not exist in older NumPys. The other ones are forcing backwards compatibility.

@blnicho blnicho merged commit ae354ae into Pyomo:main Jun 25, 2024
27 of 30 checks passed
# float96 and float128 may or may not be defined in this particular
# numpy build (it depends on platform and version).
# Register them only if they are present
if hasattr(np, 'float_'):
# Prepend to preserve previous functionality

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that float_/complex_ were simple aliases to float64/complex128, so it is not necessary to handle them for numpy 1.x, just dropping them is fully backwards compatible.

dbrnz added a commit to AnatomicMaps/flatmap-maker that referenced this pull request Aug 15, 2024
@jsiirola jsiirola mentioned this pull request Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pyomo is not compatible with Numpy 2.0.0
5 participants